﻿@model IEnumerable<LotteryVoteMVC.Models.BetOrder>
@using LotteryVoteMVC.Models
@using LotteryVoteMVC.Resources
@using LotteryVoteMVC.Utility
@{
    ViewBag.Title = @Resource.Statement;
    Layout = "~/Views/Shared/Main.cshtml";
}
@section Header
{
    <script src="@Url.Content("~/Scripts/Customer/TableBase.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/Content/TableBase.css")" rel="stylesheet" type="text/css" />
}
@{
    decimal turnover = 0, comm = 0, netwin = 0, winlost = 0, cancel = 0;
    BetOrder lastWeekTotal = ViewBag.LastWeekTotal;
}
<table>
    <thead>
        <tr>
            <td colspan="3">
                @Resource.Date
            </td>
            <td>
                @Resource.Turnover
            </td>
            <td>
                @Resource.Commission
            </td>
            <td>@Resource.Win
            </td>
            <td>
                @Resource.WinLost
            </td>
            <td>
                @Resource.Cancel
            </td>
        </tr>
    </thead>
    <tbody>
        @foreach (var order in Model)
        { 
            <tr>
                <td>
                    @Resource.ResourceManager.GetString(order.CreateTime.DayOfWeek.ToString())
                </td>
                <td>
                    @order.CreateTime.ToShortDateString()
                </td>
                <td>
                    @Resource.VietnamLottery
                </td>
                <td>
                    @order.Turnover.ToString("N")
                </td>
                <td>
                    @order.Commission.ToString("N")
                </td>
                <td>
                    @Html.ActionLink(order.NetWin.ToString("N"), "Win", "Order", new { FromDate = order.CreateTime.ToShortDateString(), ToDate = order.CreateTime.ToShortDateString() }, null)
                </td>
                <td class="@(order.DrawResult < 0 ? "red" : string.Empty)">
                    @Html.ActionLink(order.DrawResult.ToString("N"), "memberWL", new { Date = order.CreateTime.ToShortDateString() })
                </td>
                <td>
                    @Html.ActionLink(order.CancelAmount.ToString("N"), "Cancel", new { Date = order.CreateTime.ToShortDateString() })
                </td>
            </tr>
            if (order.CreateTime > lastWeekTotal.CreateTime)
            {
                turnover += order.Turnover;
                comm += order.Commission;
                netwin += order.NetWin;
                winlost += order.DrawResult;
                cancel += order.CancelAmount;
            }
            if (order.CreateTime == lastWeekTotal.CreateTime)
            { 
            <tr class="foot">
                <td colspan="2">
                    @lastWeekTotal.CreateTime.AddDays(-6).ToShortDateString()
                    -
                    @lastWeekTotal.CreateTime.ToShortDateString()
                </td>
                <td>@Resource.Total
                </td>
                <td>
                    @lastWeekTotal.Turnover.ToString("N")
                </td>
                <td>
                    @lastWeekTotal.Commission.ToString("N")
                </td>
                <td>
                    @lastWeekTotal.NetWin.ToString("N")
                </td>
                <td class="@(lastWeekTotal.DrawResult < 0 ? "red" : string.Empty)">
                    @lastWeekTotal.DrawResult.ToString("N")
                </td>
                <td>
                    @lastWeekTotal.CancelAmount.ToString("N")
                </td>
            </tr>
            }
        }
    </tbody>
    <tfoot>
        <tr>
            <td>
            </td>
            <td>
            </td>
            <td>@(Resource.ThisWeek + Resource.Total)
            </td>
            <td>@turnover.ToString("N")
            </td>
            <td>@comm.ToString("N")
            </td>
            <td>@netwin.ToString("N")
            </td>
            <td class="@(winlost < 0 ? "red" : string.Empty)">@winlost.ToString("N")
            </td>
            <td>@cancel.ToString("N")
            </td>
        </tr>
    </tfoot>
</table>
